package algorithm.test;

public class Insert {
    public static void insert(Comparable[] a){
        for (int i=1;i<a.length;i++){
            for (int j=i;j>=1;j--){
                if (greater(a[j-1],a[j])){
                    exch(a,j-1,j);
                }
            }
        }
    }
    public static boolean greater(Comparable v,Comparable w){
        return v.compareTo(w)>0;
        //v是否大于w
    }

    private static void exch(Comparable[] a,int i,int j){
        Comparable t=a[i];
        a[i]=a[j];
        a[j]=t;
    }
}
